package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.pojo.vo.FormDataRepeatVO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.pro.bom.pojo.dto.BomBillListDTO;
import com.xbongbong.pro.bom.pojo.dto.BomDeleteBatchDTO;
import com.xbongbong.pro.bom.pojo.dto.BomEditAttrUpdateDTO;
import com.xbongbong.pro.bom.pojo.dto.BomUpdateByBusinessRuleDTO;
import com.xbongbong.pro.bom.pojo.vo.BomDeleteBatchVO;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessproduct.pojo.dto.BusinessProductListDTO;
import com.xbongbong.pro.businessproduct.pojo.vo.BusinessProductListVO;
import com.xbongbong.pro.common.pojo.dto.RepeatCommonConditionDTO;
import com.xbongbong.pro.customer.pojo.dto.ChangeStatusDTO;
import com.xbongbong.pro.detailtab.vo.ProductSummaryVO;
import com.xbongbong.pro.formdata.pojo.AfterSavePojo;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.product.pojo.dto.PagingProductDTO;
import com.xbongbong.pro.product.pojo.vo.PagingProductVO;
import com.xbongbong.saas.domain.entity.BomProductEntity;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;

import java.util.List;
import java.util.Map;


/**
 * @author long.rao
 * @version v1.0
 * @date 2019/1/22 10:39
 * @since v1.0
 */
public interface BomBillService {
    /**
     * Description: BOM清单保存前校验
     *
     * @param validateDataDTO saas特殊校验数据入参
     * @throws XbbException 业务异常
     * @author long.rao
     * @date 2019-01-22 10:44
     */
    void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException;

    /**
     * Description: BOM清单保存后逻辑
     *
     * @param saasFormSaveDTO saas保存数据
     * @throws XbbException 业务异常
     * @author long.rao
     * @date 2019-01-22 10:45
     */
    AfterSavePojo afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;



    /**
     * bom版本查重
     *
     * @param repeatCommonConditionDTO 查重公用DTO入参
     * @param finishedProductVersion   bom版本
     * @param bomId                    bom清单id
     * @param productId                bom清单成品产品id
     * @param isSave                是否是保存bom单
     * @return 重复数据实体
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/2/19 21:38
     */
    FormDataRepeatVO checkRepeatForBomVersion(RepeatCommonConditionDTO repeatCommonConditionDTO, String finishedProductVersion, Long bomId, Long productId,Boolean isSave) throws XbbException;

    /**
     * BOM单产品保存
     * @param productArray 产品数组
     * @param productType 产品类型 1：成品；2：物料
     * @param corpid 公司id
     * @param bomId 对应bom单的id
     * @throws XbbException
     * @author long.rao
     * @date 2019-02-01 15:19
     */
    void saveProduct(JSONArray productArray, Integer productType, String corpid, Long bomId) throws XbbException;

    /**
     * 获取bom产品
     *
     * @param businessProductListDTO
     * @param dataList 数据data
     * @throws XbbException
     * @return BomVo
     * @author long.rao
     * @date 2019-02-25 17:24
     */
    BusinessProductListVO getBomProductList(BusinessProductListDTO businessProductListDTO, JSONObject dataList) throws XbbException;

    /**
     * 根据产品判断是否有可用的bom单（启用， 不在审批中）
     *
     * @param productId 产品id
     * @param corpid 公司id
     * @return 是否有可用的bom单
     * @author long.rao
     * @date 2019-03-02 17:34
     */
    boolean hasEnabledBom(Long productId, String corpid) throws XbbException;

    /**
     * 批量删除
     * @author 吴峰
     * @date 2019/3/6 21:12
     * @param bomDeleteBatchDTO
     * @return com.xbongbong.pro.bom.pojo.vo.BomDeleteBatchVO
     * @throws XbbException 业务异常
     */
    BomDeleteBatchVO deleteBatch(BomDeleteBatchDTO bomDeleteBatchDTO) throws XbbException;

    /**
     * 批量编辑某个字段
     * @author 吴峰
     * @date 2019/3/20 15:22
     * @param bomEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(BomEditAttrUpdateDTO bomEditAttrUpdateDTO) throws XbbException;

    /**
     * 模拟生产获取的bom数据
     * @param bomBillListDTO
     * @return
     * @throws XbbException
     */
    PaasFormDataEsListVO list(BomBillListDTO bomBillListDTO) throws XbbException;

    /**
     * 修改BOM状态
     *
     * @param changeStatusDTO 入参
     * @author GuoJun.HU
     * @since V1.0
     * @return BaseVo
     * @throws XbbException
     * @date 2019/6/4 20:04
     */
    BaseVO changeStatus(ChangeStatusDTO changeStatusDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     * @author long.rao
     * @date 2019-05-06 15:03
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 格式化导出数据
     *
     * @param paasFormDataESList    导出的数据
     * @param formDataListDTO       查询数据的入参
     * @param fieldAttrList         表单解释
     * @author GuoJun.HU
     * @since V1.0
     * @date 2019/5/27 10:15
     * @throws XbbException XbbException
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 根据业务规则，更新bom
     * @author 吴峰
     * @date 2019/8/19 15:56
     * @param bomUpdateByBusinessRuleDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void updateBatchByBusinessRule(BomUpdateByBusinessRuleDTO bomUpdateByBusinessRuleDTO) throws XbbException;

    /**
     * 汇总bom单产品信息（详情页，几种产品几件）
     *
     * @param businessProductListDTO 入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-28 10:23
     */
    ProductSummaryVO summaryProductList(BusinessProductListDTO businessProductListDTO) throws XbbException;

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    PagingProductVO getPagingProduct(PagingProductDTO pagingProductDTO) throws XbbException;

    JSONObject formatSingleProduct(BomProductEntity entity);

    JSONObject formatSingleMaterial(BomProductEntity entity);

    /**
     * Description: 获取bom清单名称集合
     * @param handoverIdSet
     * @param corpid
     * @author 刘阳
     * @date 2020/1/8 2:41 PM
     * @since v1.0
     */
    Map<Long, String> getBomBillNameMap(List<Long> handoverIdSet, String corpid) throws XbbException;

    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;
}
